package com.kevin.test;

import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.util.Log;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity implements ServiceConnection {
	private final static String TAG = "MainActivity";
	private MyServiceAIDL myServiceAIDL;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	public void onClkStartService(View v) {
		Intent intent = new Intent(this, MyService.class);
		startService(intent);
	}
	
	public void onClkStopService(View v) {
		Intent intent = new Intent(this, MyService.class);
		stopService(intent);
	}
	
	public void onClkBindService(View v) {
		Intent intent = new Intent(this, MyService.class);
		bindService(intent, this, BIND_AUTO_CREATE);
	}

	public void onClkUnbindService(View v) {
		unbindService(this);
	}
	
	@Override
	public void onServiceConnected(ComponentName name, IBinder service) {
		Log.d(TAG, "on service connected");
		myServiceAIDL = MyServiceAIDL.Stub.asInterface(service);
		try {
			System.out.println("2 + 3 = " + myServiceAIDL.plus(2, 3));
			System.out.println(myServiceAIDL.toUpperCase("fdasfsdaf"));
		} catch (RemoteException exception) {
			exception.printStackTrace();
		}
	}

	@Override
	public void onServiceDisconnected(ComponentName name) {
		Log.d(TAG, "on service disconnected");
	}
}
